﻿<%@ page contentType="text/html; charset=UTF-8" %>

<!-- 角色管理 -->


<div class="bar_seach_div">

查询条件：<input id="s_menurole_roleName" name="s_menurole_roleName" type="text" class="box-input">&nbsp;&nbsp;
<input id="s_tsrole" type="button" class="btns" value="查  询">
</div>

<div style="padding: 5px;"><table id="menurole_grid"></table></div>   
<div style="padding: 5px;"><div id="menurole_page"></div>


<div id="menurole_dialog_index" title=" 角色管理操作"  class="easyui-dialog" >
<form id="menurole_form_index" name="menurole_form_index" style="width:526px;" class="ui-form" method="POST">
    <div id="menurole_index_errmsg"></div>
    <table width="100%" align="center" style="font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #666666;border-collapse: collapse;"> 

	<tr>
        <td class="bluetd" align="right">角色名：</td>
        <td class="bluetd" align="left">
          <input id="menurole_roleName_index"   readonly="readonly"  type="text"/>
        </td>
     </tr>
   
     <tr style="height:320px">
        <td class="bluetd2" align="right" >菜单：</td>
        <td class="bluetd2" align="left">  
           <div id = "syteDemo_parentIdComboList" style="width:200px;height:200px;overflow-x:auto;overflow-y:auto;"></div> 
        </td>
     </tr>

      <tr>
        <td colspan="2" align="center">
         <input type="button" class="btns" id="menurole_index_bt" value="提  交" style="margin-top:8px;" />&nbsp;&nbsp;
         <input type="button" class="btns" id="menurole_close" value="关  闭" style="margin-top:8px;" />
      </td>
</tr>
</table>
</form>
</div> 

<script>

	//关闭弹出窗口
	closeUIDialog('menurole_dialog_index');
    var tsrolevalidate,tsroleids='',tsrolesave=true;//本页面变量
     /**jqGrid列表*/
	jQuery("#menurole_grid").jqGrid({
		// caption: 
	    //     '<a href="javascript:fun_menurole_add()"  class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-edit\'">新增</a>' +
	    //     '<a href="javascript:fun_menurole_update()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-save\'">修改</a>' +
	    //     '<a href="javascript:fun_menurole_delete()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-cancel\'">删除</a>',
        datatype: "json", //JSON格式数据
        hidegrid: false, //不显示收缩
        url:'system/Role/list.do', //请求后台返回列表数据的URL 
        forceFit: false,//调整宽度不改变表格宽度
        //width: jqGridWidth,   //resources/js/constant.js
        //height: jqGridHeight, //resources/js/constant.js
        autowidth:false,   //取消容器的自动宽度
        colNames:[
        '编号'
        ,'角色名'
        ,'备注'
        ,'状态'
        ,'创建时间'
        ,'修改时间'
        //,'操作'
	    ],
	    //要呈现字段的属性设置
	    //sortable:设置该字段是否进行排序,sorttype:排序的数据类型 
        colModel:[
        {name:'id',index:'id', width:2,sorttype:'int',sortable:false}  
        ,{name:'roleName',index:'roleName',width:80,sortable:false}
        ,{name:'roleDesc',index:'roleDesc',width:80,sortable:false}
        ,{name:'roleStatus',index:'roleStatus',width:80,sortable:false ,formatter: "select", editoptions:{value:"1:有效;2:无效;0:未知"}}
        ,{name:'createDateString',index:'createDateString',width:90,sortable:false}
        ,{name:'updateDateString',index:'updateDateString',width:90,sortable:false}
        //,{name:'act',        index:'act',   align:'center',     width:150}
        ],
        multiselect: true,//禁止多选
        multiboxonly:true,
        toolbar:[true,'top'],
        rowNum:10, 
        rowList:[10,20,30,50,100,500], 
        viewrecords: true, 
        sortname:  "roleId" , //默认排序的列名    
        sortorder: "desc", 
        pager: '#menurole_page', 
        jsonReader: {     
          root: 'dataRows',   
          repeatitems : false     
        }
        //,caption:'角色管理 列表'       
       // ,gridComplete: function(){  
          //  var ids = $("#menurole_grid").jqGrid('getDataIDs');  
           // for(var i=0, j=ids.length; i < j; i++){  
              //  var cl = ids[i];  
               // be = "<input style='height:22px;width:40px;' type='button' value='编辑' onclick=\"fun_menurole_update();\"  />&nbsp;&nbsp;";   
                //se = "<input style='height:22px;width:40px;' type='button' value='保存' onclick=\"$('#jqGridId').saveRow('"+cl+"');\"  />&nbsp;&nbsp;";  
               // se = "<input style='height:22px;width:40px;' type='button' value='删除' onclick=\"fun_menurole_delete();\"  />&nbsp;&nbsp;";   
               // ce = "";
                //$("#menurole_grid").jqGrid('setRowData',ids[i], {act: be + se + ce});  
           // }
        //}
    })
    
    $("#t_menurole_grid").removeClass("ui-userdata ui-state-default"); //删样式
	$("#t_menurole_grid").append("<div style='height:32px;' class='ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix'><span class='ui-jqgrid-title'>"
	  //+"<a data-options='plain:true,iconCls:\'icon-edit\'' class='easyui-linkbutton l-btn l-btn-plain' href='javascript:fun_menurole_add()' group='' id=''><span class='l-btn-left'><span class='l-btn-text icon-edit l-btn-icon-left'>新增</span></span></a>"
	  +"<a data-options='plain:true,iconCls:\'icon-save\'' class='easyui-linkbutton l-btn l-btn-plain' href='javascript:fun_menurole_update()' group='' id=''><span class='l-btn-left'><span class='l-btn-text icon-save l-btn-icon-left'>角色分配菜单</span></span></a>"
	  //+"<a data-options='plain:true,iconCls:\'icon-cancel\'' class='easyui-linkbutton l-btn l-btn-plain' href='javascript:fun_menurole_delete()' group='' id=''><span class='l-btn-left'><span class='l-btn-text icon-cancel l-btn-icon-left'>删除</span></span></a>"
	  +"</span></div> ");//列表头

    //$("#t_menurole_grid").append("<div class='bar_grid_add_div' > <a href='javascript:void(0)' onclick=\"fun_menurole_add()\" >新增</a></div>");//列表头
    //$("#t_menurole_grid").hide();//隐藏标题栏
    jQuery("#menurole_grid").jqGrid('hideCol',['id']);//隐藏列
    $("#menurole_grid").closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'hidden' });//隐藏横向滚动条
    
    var menurole_list_saveflag = true;
    
    /***/
    $('#menurole_index_bt').unbind('click');
   
    //关闭窗口
    $('#menurole_close').click(function(){
        $("#menurole_dialog_index").dialog('close');
    })
    
    /**点击按妞*/
    $('#menurole_index_bt').click(function(){
         menurole_update_submit(); 
     })
     
 

     /**修改操作*/
     function fun_menurole_update(){
         var id =$("#menurole_grid").jqGrid('getGridParam','selrow');
         if(typeof(id) =="string"){
             rowData=jQuery("#menurole_grid").jqGrid('getRowData',id);  
 		    //$("#menurole_dialog_index").dialog('option' , 'title',['修改 角色管理']);
 		    $("#menurole_form_index")[0].reset();
 		    //tsrolevalidate.resetForm(); //重置验证状态
 		    //$("#menurole_dialog_index").dialog("open");
 		    /**修改加载数据*/
 		    from_initbaractCombox(rowData.id);
 		    $("#menurole_roleName_index").val(rowData.roleName);
 		    openUIDialog('menurole_dialog_index', true, 560, 450);
              
             tsrolesave=false;
         }else{
        	 $.messager.alert('操作提示', '请至少选择一条记录再操作!'); 
         }
 	} 
 	 
    //修改提交
    function  menurole_update_submit(){
    	var nodes = getChildNodes();
    	var baractJson="{'roleId':'"+rowData.id+"','nodes':'"+nodes+"'}";
    	$.ajax({
            url : 'system/Menu/rolemenu.do',
            type:'POST',
            dataType : 'json',
            async:false,
            data: {
            	json : baractJson
            },
            beforeSend:function(){
                //jBeforeSend();
            },
            complete :function(){
                //jCompleted();
            },
            error:function(event){
                //jError(event);
            },
            success:function(json){
                if(json.success){
                	//关闭弹出窗口
                	closeUIDialog('menurole_dialog_index');
                    $("#menurole_grid").trigger("reloadGrid");
                    $.messager.alert('操作提示', '操作成功!');
                }else{
               	 $.messager.alert('操作提示', '操作失败!');
                }
            }
        });
    }
	 
	//注意:web服务器 utf-8配置
	$('#s_tsrole').click(function(){
         var s_roleName=encodeURI($('#s_menurole_roleName').val());
         $("#menurole_grid").setGridParam({url:'system/Role/list.do?s_roleName='+s_roleName});
         $("#menurole_grid").trigger("reloadGrid");
    })
    
    /** jqgrid宽度高度自适应 begin */ 
    doResize();
	var t=document.documentElement.clientWidth;  
	window.onresize = function(){  
		if(t != document.documentElement.clientWidth){ 
		t = document.documentElement.clientWidth; 
		doResize(); 
		} 
	} 
    
	function doResize() { 
		var ss = getPageSize(); 
		$("#menurole_grid").jqGrid('setGridWidth', ss.WinW-350).jqGrid('setGridHeight', ss.WinH-300); 
	}
	
	function getPageSize() { 
		//http://www.blabla.cn/js_kb/javascript_pagesize_windowsize_scrollbar.html 
		var winW, winH; 
		if(window.innerHeight) {// all except IE 
		winW = window.innerWidth; 
		winH = window.innerHeight; 
		} else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode 
		winW = document.documentElement.clientWidth; 
		winH = document.documentElement.clientHeight; 
		} else if (document.body) { // other 
		winW = document.body.clientWidth; 
		winH = document.body.clientHeight; 
		}  // for small pages with total size less then the viewport  
		return {WinW:winW, WinH:winH}; 
	}
	/** jqgrid宽度高度自适应 begin */
     
	
  
	
	function from_initbaractCombox(roleId) {
		$.ajax({  
			url:"system/Menu/dataTree.do",
			  cache: false,  
			  dataType:"json",  
			  data: { roleId : roleId },
			  success: function(result){
				  //alert("ok"+result.list[0].id);
				  var feiqumingxiarr = new Array();
				  feiqumingxiarr =result.data;
			    $("#syteDemo_parentIdComboList").tree({  
			    	checkbox: true,
			        data : feiqumingxiarr,  
			        valueField : 'id',  
			        textField : 'name'
			    });
			  },
			  error : function(){
				  alert("error");
			  }
			});
	}
	function getChildNodes(){
        var node = $('#syteDemo_parentIdComboList').tree('getChecked');  
        var nodes = "";  
        for(var i=0;i<node.length;i++){
            nodes += "" + node[i].id + "" + ",";
        }
        return nodes;
    }

	
	
</script>
